// 工具方法
jQuery.support.cors = true;
(function($) {
     window.console = window.console || (function () {
        var c = {};
        c.log = c.warn = c.debug = c.info = c.error = c.time = c.dir = c.profile = c.clear = c.exception = c.trace = c.assert = function () { };
        return c;
    })();
    if (!window.Util) {
        window.Util = {};
    }
    /*
     * 序列化表单元素，区别于jQuery 的serialize和serializeArray方法
     */
    $.fn.serializeObject = function() {
        var o = {};
        var a = this.serializeArray();
        $.each(a, function() {
            if (o[this.name]) {
                if (!o[this.name].push) {
                    o[this.name] = [o[this.name]];
                }
                o[this.name].push(this.value || '');
            } else {
                o[this.name] = this.value || '';
            }
        });
        return o;
    };
    $.extend(Util, {
        /*
        附件地址
        */
        FileRUrl: "",
        AjaxRUrl: "/hfesewb/rest/hfService/",
        /* 获取URL地址参数
         * prop:参数名
         */
        getUrlParams: function(prop) {
            var params = {},
                query = location.search.substring(1),
                arr = query.split('&'),
                rt;

            $.each(arr, function(i, item) {
                var tmp = item.split('='),
                    key = tmp[0],
                    val = tmp[1];

                if (typeof params[key] == 'undefined') {
                    params[key] = val;
                } else if (typeof params[key] == 'string') {
                    params[key] = [params[key], val];
                } else {
                    params[key].push(val);
                }
            });
            rt = prop ? params[prop] : params;
            return rt;
        },

        // 适配f9中的response格式
        ajax: function(options) {
            options = $.extend({}, {
                type: 'POST',
                dataType: 'json',
                dataFilter: function(data, type) {
                    if (type == 'json') {
                        data = JSON.parse(data);

                        // TODO: 这里可以对data做些统一处理，权限处理等

                        data = data.UserArea;

                        if (typeof data == 'object') {
                            data = JSON.stringify(data);
                        }

                    }

                    return data;
                },
                error: Util._ajaxErr
            }, options);

            //options.url = SrcBoot.getPath(options.url);

            return $.ajax(options);
        },

        // empty function
        noop: function() {},

        // 去除html标签中的换行符和空格
        clearHtml: function(html) {
            return html.replace(/(\r\n|\n|\r)/g, "")
                .replace(/[\t ]+\</g, "<")
                .replace(/\>[\t ]+\</g, "><")
                .replace(/\>[\t ]+$/g, ">");
        },
        //字符串转时间，兼容IE7等浏览器
        stringToDate: function(DateStr) {
            var myDate, temp;
            if (DateStr.indexOf('-') != -1) {
                temp = DateStr.replace(/-/g, '/').toString();
                myDate = new Date(Date.parse(temp));
            } else if (DateStr.indexOf('.') != -1) {
                temp = DateStr.replace(/\./g, '/').toString();
                myDate = new Date(Date.parse(temp));
            } else {
                myDate = new Date(DateStr);
            }
            return myDate;
        },
        _ajaxErr: function(jqXHR, textStatus, errorThrown) {
            //console.error('status: %s, error: %s', textStatus, errorThrown);
        }
    });
}(jQuery));
(function($) {
    // 加载头尾代码片段
    $.ajaxSettings.async = false; //同步加载
    ///home no #header
    if ($("#header").length > 0) {
        var p = $("#header").data("ps");
        var headurl = "/include/header.inc.html";
        if (p == "person") { //用户中心
            headurl = "/template/include/userheader.html";
        }
        $("#header").load(headurl, function(data) {
            $(this).html(data);
            //InitDate();
            setCurrrentNav();
            $.ajaxSettings.async = true;
            if (p == "person") {
                var username = $.cookie('userName');
                if (username == null || username == "") {
                    alert("请先登录");
                    window.open("/index.html", "_self");
                }
            } else {
                //通知公告
                /* $(".ewb-notice").slide({
                    mainCell: ".ewb-notice-bd",
                    effect: "topLoop",
                    autoPlay: true
                }); */
            }
            $(".building").click(function(event) {
                /* nav building */
                alert("功能暂未开放，敬请期待！");
            });
        });
    } else {
        //首页
        // 输入框placeholder
		//$('[placeholder]').placeholder();
		//点击回到顶部
		$('.ewb-side-icon4').on('click',function(event) {
			event.preventDefault();
			$('body,html').animate({ scrollTop: 0 }, 200);
			return false;
		});
        //通知公告
        /* $(".ewb-notice").slide({
            mainCell: ".ewb-notice-bd",
            effect: "topLoop",
            autoPlay: true
        }); */
        //InitDate();
        setCurrrentNav();
        $(".building").click(function(event) {
            /* nav building */
            alert("功能暂未开放，敬请期待！");
        });
    }
    $("#footer").load("/include/footer.inc.html");
	
	$('.ewb-search-contant').hover(function(event) {
		 $('.ewb-top').addClass('hasopen');
	}, function(e) {
		 $('.ewb-top').removeClass('hasopen');
	});
		
    //设置当前导航
    function setCurrrentNav() {
        var curl = location.href;
        $(".ewb-nav-item").removeClass("current");
        var home = true;
        $(".ewb-nav-item").not(".building").each(function(index, el) {
            if (index > 0) {
                var turl = getNUrl($(this).attr("href"));
                if (curl.indexOf(turl) > -1) {
                    $(this).addClass('current');
                    home = false;
                }
            }
        });
        if (home) {
            $(".ewb-nav-item").first().addClass("current");
        }
    }
    //获取地址url中的分类信息,兼容IE7？待完善
    function getNUrl(surl) {
        surl = surl || '/'; //:IE7兼容模式下，地址会补全
        surl = surl.replace(location.host, "").replace("http:", "").replace(/\/\//g, "/");
        var s = surl.split('/');
        var result = surl;
        for (var i = 0; i < s.length; i++) {
            if (s[i] != "") {
                result = s[i];
                break;
            }
        }
        return result;
    }
}(jQuery));

function initArray() {
    this.length = initArray.arguments.length;
    for (var i = 0; i < this.length; i++) {
        this[i + 1] = initArray.arguments[i];
    }
}
//now:
/* function InitDate() {
    var today = new Date();
    var d = new initArray(
        "星期日",
        "星期一",
        "星期二",
        "星期三",
        "星期四",
        "星期五",
        "星期六");
    document.getElementById("now").innerHTML = " " + today.getFullYear() + "年" + (today.getMonth() + 1) + "月" + today.getDate() + "日 " + d[today.getDay() + 1] + "";
} */

//点击回到顶部
$('.ewb-side-icon4').on('click',function(event) {
	event.preventDefault();
	$('body,html').animate({ scrollTop: 0 }, 200);
	return false;
});
